﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/06/17
 * 
 * 功能说明：模块选择功能模块，功能模块选择表单
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class UserControls_ModuleSelect : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindModule();
        }
    }

    /// <summary>
    /// 获取和设置模块标识
    /// </summary>
    public string SelectModule
    {
        get { return this.ddlModule.SelectedValue; }
        set
        {
            BindModule();
            this.ddlModule.SelectedValue = value;
        }
    }

    /// <summary>
    /// 获取和设置功能模块编号
    /// </summary>
    public string SelectModel
    {
        get { return this.ddlModel.SelectedValue; }
        set
        {
            BindModel();
            this.ddlModel.SelectedValue = value;
        }
    }

    /// <summary>
    /// 获取和设置表单编号
    /// </summary>
    public string SelectModelForm
    {
        get { return this.ddlModelForm.SelectedValue; }
        set
        {
            BindModelForm();
            this.ddlModelForm.SelectedValue = value;
        }
    }

    private void BindModule()
    {
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetDataTable("moduleMark,moduleName", "Whir_Module", "", "");
        this.ddlModule.DataSource = dt.DefaultView;
        this.ddlModule.DataValueField = "moduleMark";
        this.ddlModule.DataTextField = "moduleName";
        this.ddlModule.DataBind();

        this.ddlModule.Items.Insert(0, new ListItem("-- 模块列表 --", "-1"));
    }

    private void BindModel()
    {
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetDataTable("modelID,modelName", "Whir_Model", "moduleMark='" + this.ddlModule.SelectedValue + "'", "");
        this.ddlModel.DataSource = dt.DefaultView;
        this.ddlModel.DataValueField = "modelID";
        this.ddlModel.DataTextField = "modelName";
        this.ddlModel.DataBind();

        this.ddlModel.Items.Insert(0, new ListItem("-- 功能模块列表 --", "-1"));
    }

    private void BindModelForm()
    {
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetDataTable("modelFormID,formName", "Whir_ModelForm", "modelID=" + this.ddlModel.SelectedValue, "");
        this.ddlModelForm.DataSource = dt.DefaultView;
        this.ddlModelForm.DataValueField = "modelFormID";
        this.ddlModelForm.DataTextField = "formName";
        this.ddlModelForm.DataBind();
    }

    protected void ddlModule_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ddlModule.SelectedValue != "-1")
            BindModel();
        else
            this.ddlModel.Items.Clear();

        this.ddlModelForm.Items.Clear();
    }

    protected void ddlModel_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ddlModel.SelectedValue != "-1")
            BindModelForm();
        else
            this.ddlModelForm.Items.Clear();
    }
}
